/**
 *
 */
package com.codi.bus.core.dao.impl;

import com.codi.base.dao.BaseDAOImpl;
import com.codi.bus.core.dao.LookupDao;
import com.codi.bus.core.domain.Lookup;
import com.codi.bus.core.domain.LookupKey;
import com.google.common.base.Preconditions;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Administrator
 */
@Repository("lookupDao")
public class LookupDaoImpl extends BaseDAOImpl<Lookup> implements LookupDao {

    @Override
    public boolean insertSelective(Lookup lookup) {
        Preconditions.checkNotNull(lookup);
        Preconditions.checkNotNull(lookup.getRuleType());
        return this.insert(generateStatement("insertSelective"), lookup) >= 1;
    }

    /**
     * 根据字典类型查询数据
     */
    public List<Lookup> getLookupByType(String type) {
        return this.findList(generateStatement("queryLookupByType"), type);
    }

    @Override
    public List<Lookup> getOrganBabies(String type) {
        return this.findList(generateStatement("queryOrganBabiesLookupByType"), type);
    }

    @Override
    public Lookup getLookupByKey(LookupKey key) {
        return this.getObject(generateStatement("queryLookupByKey"), key);
    }

    @Override
    public int deleteLookupByKey(LookupKey key) {
        return this.delete(generateStatement("deleteByPrimaryKey"), key);
    }


    @Override
    public Lookup getOrganBaby(LookupKey key) {
        return this.getObject(generateStatement("getOrganBaby"), key);
    }

    @Override
    public boolean updateByRuleType(Lookup lookup) {
        Preconditions.checkNotNull(lookup);
        Preconditions.checkNotNull(lookup.getRuleType());

        return this.update(generateStatement("updateByRuleType"), lookup) >= 1;
    }

    @Override
    public boolean updateByRuleTypeAndRuleValue(Lookup lookup) {
        Preconditions.checkNotNull(lookup);
        Preconditions.checkNotNull(lookup.getRuleType());
        Preconditions.checkNotNull(lookup.getRuleValue());

        return this.update(generateStatement("updateByPrimaryKeySelective"), lookup) >= 1;
    }


}
